package com.sskj.one.mine;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.widget.TextView;

import com.sskj.common.util.ClickUtil;
import com.sskj.lib.base.BaseActivity;
import com.sskj.lib.bean.UserData;
import com.sskj.lib.model.room.UserViewModel;
import com.sskj.one.R;
import com.sskj.one.component.DaggerUserDataComponent;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author Hey
 * Create at  2019/05/22
 */
public class SafeCenterActivity extends BaseActivity<SafeCenterPresenter> {

    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.tv_change_login)
    TextView tvChangeLogin;
    @BindView(R.id.tv_pay_pwd)
    TextView tvPayPwd;
    @BindView(R.id.tv_pay_pwd_type)
    TextView tvPayPwdType;
    @Inject
    UserViewModel userViewModel;

    private UserData userData;

    @Override
    public int getLayoutId() {
        return R.layout.app_activity_safe_center;
    }

    @Override
    public SafeCenterPresenter getPresenter() {
        return new SafeCenterPresenter();
    }

    @Override
    public void initView() {
        DaggerUserDataComponent.create().inject(this);
        userViewModel.getUsers().observe(this, users -> {
            if (users != null && users.size() > 0) {
                userData = users.get(0);
                if ("0".equals(userData.getIs_set_tpwd())) {
                    tvPayPwdType.setText("未设置");
                    tvPayPwdType.setTextColor(ContextCompat.getColor(this, R.color.color787));
                } else if ("1".equals(userData.getIs_set_tpwd())) {
                    tvPayPwdType.setText("已设置");
                    tvPayPwdType.setTextColor(ContextCompat.getColor(this, R.color.theme));
                }
            } else {
                userData = null;
            }
        });

        tvTitle.setText("安全中心");
        ClickUtil.click(300, tvChangeLogin, () -> {
            ChangeLoginActivity.start(SafeCenterActivity.this);
        });
        ClickUtil.click(300, tvPayPwd, () -> {
            PayPwdActivity.start(SafeCenterActivity.this);
        });
    }

    @Override
    public void initData() {

    }

    public static void start(Context context) {
        Intent intent = new Intent(context, SafeCenterActivity.class);
        context.startActivity(intent);
    }
}
